<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn1">GET</button>
    <button id="btn2">POST</button>
    <button id="btn3">PUT</button>
    <button id="btn4">PATCH</button>
    <button id="btn5">DELETE</button>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <script>
        /* document.getElementById("btn1").onclick =async function(){
            const response = await axios({
                method:'GET',
                url:'http://localhost:3000/posts',
            })
            console.log(response.data);
        }
        document.getElementById("btn2").onclick=async function(){
            const response = await axios({
                method:'POST',
                url:'http://localhost:3000/posts',
                data:{
                    title:'天上的醒醒有几颗',
                    author:'小雨'
                }
            })
            console.log(response.data);
        }
        document.getElementById("btn3").onclick=async function(){
            const response = await axios({
                method:'PUT',
                url:'http://localhost:3000/posts/3',
                data:{
                    author:'小雨'
                }
            })
            console.log(response.data);
        }
        document.getElementById("btn4").onclick=async function(){
            const response = await axios({
                method:'PATCH',
                url:'http://localhost:3000/posts/3',
                data:{
                    author:'da雨',
                    age:18
                }
            })
            console.log(response.data);
        } */
        // 查询所有
        // document.getElementById("btn1").onclick =async function(){
        //     const response = await axios({
        //         method:'GET',
        //         url:'http://localhost:3000/posts',
        //     })
        //     console.log(response.data);
        // }
        //查询一条
        /* btn1.onclick =async function(){
            const response = await axios({
                method:'GET',
                url:'http://localhost:3000/posts/2'
            })
            console.log(response.data);
        } */
        //分页查询
        /* btn1.onclick =async function(){
            const response = await axios({
                method:'GET',
                url:'http://localhost:3000/posts',
                params:{
                    _page:1,
                    _limit:3
                }
            })
            console.log(response.data);
        } */
        //slice _start _end _limit
       /*  btn1.onclick =async function(){
            const response = await axios({
                method:'GET',
                url:'http://localhost:3000/posts',
                params:{
                    _start:2,
                    _limit:3
                }
            })
            console.log(response.data);
        } */
        //模糊搜索
        btn1.onclick =async function(){
            const response = await axios({
                method:'GET',
                url:'http://localhost:3000/posts',
                params:{
                    // q:'小雨',
                    // author:'小雨'
                    // id:8
                    title_like:3
                }
            })
            console.log(response.data);
        }
    </script>
</body>
</html>